export default {
	
	
	getTimeDifference(oldDate,nowDate){
		if(!oldDate)return
		let oldTime = new Date(oldDate).getTime()
		let newTime = null
		if(nowDate){
			newTime = new Date(nowDate).getTime()
		}else{
			newTime = new Date().getTime()
		}
		let differnceTime = newTime - oldTime
		let day =  Math.floor(differnceTime/(24*3600*1000))
		let leave1 = differnceTime%(24*3600*1000)    //计算天数后剩余的毫秒数  
		let hours = Math.floor(leave1/(3600*1000))  
		let leave2 = leave1%(3600*1000)  //计算小时数后剩余的毫秒数  
		let minutes = Math.floor(leave2/(60*1000))     //计算相差分钟数  
		let leave3 = leave2%(60*1000)      //计算分钟数后剩余的毫秒数  
		let seconds=Math.round(leave3/1000)
		// alert(" 相差 "+day+"天 "+hours+"小时 "+minutes+" 分钟"+seconds+" 秒")  
		let joinStr = ''
		if(day > 0){
			joinStr+= day + '天'
		}
		if(hours > 0){
			joinStr+= hours + '时'
		}
		if(minutes > 0){
			joinStr+= minutes + '分'
		}
		if(seconds > 0){
			joinStr+= seconds + '秒'
		}
		return {
			day,
			hours,
			minutes,
			seconds,
			joinStr
		}
	},
	
	 // 加法运算
	numAdd(num1, num2) {
		// debugger
		let result = null
		if (!num1 && !num2) {
			result = 0
		} else {
			var baseNum, baseNum1, baseNum2;  
			try {  
				baseNum1 = num1.toString().split(".")[1].length;  
			} catch (e) {  
				baseNum1 = 0;  
			}  
			try {  
				baseNum2 = num2.toString().split(".")[1].length;  
			} catch (e) {  
				baseNum2 = 0;  
			}  
			baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));  
			result = (num1 * baseNum + num2 * baseNum) / baseNum;  
		}
		return result
	},
	// 乘法运算
	numMulti(num1, num2) {
			let result = null
		if (!num1 || !num2) {
			result = 0
		} else {
			var baseNum = 0;  
			try {  
				baseNum += num1.toString().split(".")[1].length;  
			} catch (e) {
			
			}  
			try {  
				baseNum += num2.toString().split(".")[1].length;  
			} catch (e) {  
			}  
			result = Number(num1.toString().replace(".", "")) * Number(num2.toString().replace(".", "")) / Math.pow(10, baseNum);  
		}
		
		return result
	},
	// 除法运算
	numDiv(num1, num2) {  
		let result = null
		if (!num1 || !num2) {
			result = 0
		} else {
			var baseNum1 = 0, baseNum2 = 0;  
			var baseNum3, baseNum4;  
			try {  
				baseNum1 = num1.toString().split(".")[1].length;  
			} catch (e) {  
				baseNum1 = 0;  
			}  
			try {  
				baseNum2 = num2.toString().split(".")[1].length;  
			} catch (e) {  
				baseNum2 = 0;  
			}  
		
			baseNum3 = Number(num1.toString().replace(".", ""));  
			baseNum4 = Number(num2.toString().replace(".", ""));  
			result = (baseNum3 / baseNum4) * Math.pow(10, baseNum2 - baseNum1);  
		}
		return result
		
	}  
}
